// useMixin.js
import { productDetail } from '@/api/goods'
export function useMixin() {
	const seeStock = async id => {
		const res = await productDetail(id)
		return res
	}
	const checkStockIsEnough = async (goodItem, currentNum,cartList) => {
		const goodObj = await seeStock(goodItem.id)
		console.log('goodObj:', goodObj)
		let productValueCopy = goodObj.productValue[goodItem.valueStr]
		const match = cartList.find(
			item => item.id === productValueCopy.productId && item.valueStr === productValueCopy.sku
		)
		let hasNum = match ? match.number : 0
		if (productValueCopy.stock < hasNum + currentNum) {
			uni.showToast({
				title: `商品库存不足,仅剩${productValueCopy.stock}件`,
				icon: 'none',
			})
			return false
		}
		return true
	}
	return {
		checkStockIsEnough,
        seeStock
	}
}
